//
//  ObserveManager.swift
//  ObserveTiming
//
//  Created by JY_NEW on 2021/10/30.
//

import Foundation

@dynamicMemberLookup
public struct OCObserveRouter<OCType: NSObject, OBType> {
    let obj: OCType
    let ob: OBType
    
    // MARK: KVO
    
    public subscript<ValueType>(dynamicMember path: KeyPath<OCType, ValueType>) -> OCPropertyObserveManager<OCType, ValueType, Void, OBType> {
        return OCPropertyObserveManager(obj: obj, ob: ob)
    }
    
    // MARK: 黑魔法
    
    public func method(_ selector: Selector) -> OCMethodObserveManager<OCType, OBType> {
        return OCMethodObserveManager(obj: obj, ob: ob)
    }
    
    // MARK: Delegate
    
    public subscript<ValueType>(dynamicMember path: KeyPath<OCType, Optional<ValueType>>) -> OCPropertyObserveManager<OCType, Optional<ValueType>, ValueType, OBType> {
        return OCPropertyObserveManager(obj: obj, ob: ob)
    }
    
    // MARK: Notification
    
    // MARK: 自定义事件
}

// MARK: Delegate

extension OCPropertyObserveManager where OptionalValueType: NSObjectProtocol {
    public func method(_ selector: Selector) -> OCDelegateObserveManager<OCType, OptionalValueType, OBType> {
        return OCDelegateObserveManager(obj: obj, ob: ob)
    }
}

@dynamicMemberLookup
public struct OCUnobserveRouter<OCType: NSObject, OBType> {
    let obj: OCType
    let ob: OBType
    
    // MARK: KVO
    
    public subscript<ValueType>(dynamicMember path: KeyPath<OCType, ValueType>) -> OCPropertyUnobserveManager<OCType, ValueType, Void, OBType> {
        return OCPropertyUnobserveManager(obj: obj, ob: ob)
    }
    
    // MARK: 黑魔法
    
    public func method(_ selector: Selector) -> OCMethodUnobserveManager<OCType, OBType> {
        return OCMethodUnobserveManager(obj: obj, ob: ob)
    }
    
    // MARK: Delegate
    
    public subscript<ValueType>(dynamicMember path: KeyPath<OCType, Optional<ValueType>>) -> OCPropertyUnobserveManager<OCType, Optional<ValueType>, ValueType, OBType> {
        return OCPropertyUnobserveManager(obj: obj, ob: ob)
    }
}

// MARK: Delegate

extension OCPropertyUnobserveManager where OptionalValueType: NSObjectProtocol {
    public func method(_ selector: Selector) -> OCDelegateUnobserveManager<OCType, OptionalValueType, OBType> {
        return OCDelegateUnobserveManager(obj: obj, ob: ob)
    }
}
